#TODO 导包
import allure
import pytest
from faker import Faker
import conftest
from PO.base.get_driver import GetDriver
from PO.page.page_user_home import PageUserhome
from conftest import login_url
from utils.decorator import decorator
from utils.logger import Log

# TODO 测试类使用-------满足条件跳过
version=conftest.version
#TODO 新建测试类
@allure.feature('个人中心模块')
@pytest.mark.skipif(version=='测试',reason="正在调试其他脚本，此用例暂不执行")
class TestNewAddr():
    #TODO 初始化
    def setup_class(self):
        # TODO 创建一个Faker对象
        self.fake=Faker(locale='zh_CN')
        # TODO 初始化日志模块
        self.log = Log("新增地址用例").get_logger()
        #TODO 获取driver
        self.driver=GetDriver().get_driver(login_url)
        #TODO 获取个人中心页面对象
        self.userhome=PageUserhome(self.driver)
        with allure.step("前置条件：登录测试账号18325530003"):
            login_data=('18325530003','wsf123456','8888')
            self.userhome.base_qt_login(*login_data)
            self.log.info("登录用户：{}".format(login_data))
            #TODO allure截图
            self.userhome.base_get_allure_image()


    #TODO 结束方法
    def teardown_class(self):
        self.driver=GetDriver().quit_driver()


    @decorator
    @allure.story('地址管理')
    def test_Editnewaddr(self):
        with allure.step("测试步骤一：点击地址管理菜单"):
            self.userhome.page_click_address_manage()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤二：点击增加新地址按钮"):
            self.userhome.page_click_add_new_address()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤三：进入iframe2框架"):
            self.userhome.page_to_iframe2()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤四：填写收货人"):
            receiver_value=self.fake.name()
            self.userhome.page_input_receiver(receiver_value)
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤五：地址-选择省"):
            self.userhome.page_select_province()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤六：地址-选择市"):
            self.userhome.page_select_city()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤七：地址-选择区"):
            self.userhome.page_select_district()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤八：地址-选择镇"):
            self.userhome.page_select_twon()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤九：填写详细地址"):
            self.userhome.page_input_detail_address()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤十：填写邮政编码"):
            self.userhome.page_input_zipcode()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤十一：填写手机号"):
            self.userhome.page_input_phone()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤十二：保存收货地址"):
            self.userhome.page_click_save_new_addr()
            #TODO 退出iframe框架
            self.driver.switch_to.default_content()
            self.userhome.base_get_allure_image()

        with allure.step("测试步骤十二：删除地址"):
            self.userhome.page_click_delete_addr()
            self.userhome.base_get_allure_image()